package com.thrd.taiexhibition.ui;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.bean.BeanCityInvestArticle;

import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/3/25
 */
public class InvestmentItem extends LinearLayout {

    private LayoutInflater mLayoutInflater;
//    private View mInvestmentLayout;
    //  private LinearLayout mLayout;

    public InvestmentItem(Context context) {
        this(context,null);
    }

    public InvestmentItem(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public InvestmentItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mLayoutInflater = LayoutInflater.from(context);
//        mInvestmentLayout = mLayoutInflater.inflate(R.layout.view_investment_item,null);
//        mLayout = mInvestmentLayout.findViewById(R.id.ll_layout);
//        addView(mInvestmentLayout,LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
    }


    public void setBeanCityIndustry(List<BeanCityInvestArticle> investArticleList){
        removeAllViews();
        if(investArticleList != null && investArticleList.size() > 0){
            for (int i=0;i<investArticleList.size();i++){//final BeanCityInvestArticle mBeanCityInvestArticle:mBeanCityInvest.getInvestTypeArticleList()){
                final BeanCityInvestArticle mBeanCityInvestArticle=investArticleList.get(i);
                View view=mLayoutInflater.inflate(R.layout.include_investment_item,null);
                View v=view.findViewById(R.id.v_view);
                View vLine =view.findViewById(R.id.v_line);
                v.setVisibility(i==0?VISIBLE:GONE);
                vLine.setVisibility(i<investArticleList.size()-1?VISIBLE:GONE);
                TextView mTitle=view.findViewById(R.id.tv_title);
                TextView mContent=view.findViewById(R.id.tv_content);
                mTitle.setText(TextUtils.isEmpty(mBeanCityInvestArticle.getArticleTitle())?"":mBeanCityInvestArticle.getArticleTitle());
                mContent.setText(TextUtils.isEmpty(mBeanCityInvestArticle.getArticleDetail())?"":mBeanCityInvestArticle.getArticleDetail());
                view.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(onClickItemListener!=null){
                            onClickItemListener.onClickItemListener(mBeanCityInvestArticle);
                        }
                    }
                });
                addView(view, LayoutParams.MATCH_PARENT,getContext().getResources().getDimensionPixelSize(R.dimen.qb_px_36));
            }


        }

    }

    private OnClickItemListener onClickItemListener;

    public OnClickItemListener getOnClickItemListener() {
        return onClickItemListener;
    }

    public void setOnClickItemListener(OnClickItemListener onClickItemListener) {
        this.onClickItemListener = onClickItemListener;
    }

    public interface OnClickItemListener<BeanCityInvestArticle>{
        void onClickItemListener(com.thrd.taiexhibition.bean.BeanCityInvestArticle t);
    }
}
